package 类与对象;

public class 练习题1 {
    public static void main(String[] args) {
        demo01 demo01 = new demo01();
        double[] s = {1, 2.3, 5, 7,2};
        double[] l = null;
        Double res = demo01.max(s);
        if (res != null){
            System.out.println("最大值="+ res);
        }else {
            System.out.println("arr的输入值有误");
        }


    }
}
/*
    定义一个方法，求double数组的最大值
 */
class demo01{
    public Double max(double[] arr){
        if(arr != null && arr.length > 0){
            double max = arr[0];
            for(int i = 0; i < arr.length; i++){
                if(max < arr[i]){
                    max = arr[i];
                }
            }
            return max;
        }else {
            return null;
        }

    }
}


